﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace IGolovkine.AoA
{
    public static class MessageObservableEx
    {
        public static IObservable<T> OfType<T>(this IObservable<Message> messages) where T: Message
        {
            return from m in messages where m is T select m as T;
        }

        //
        // This is why we need Contravariance!
        //
        public static IObservable<T> OfType<T>(this IObservable<Tcp.TcpMessage> messages) where T : Tcp.TcpMessage
        {
            return from m in messages where m is T select m as T;
        }

        public static IObservable<T> OfType<T>(this IObservable<Tcp.TcpConnectionMessage> messages) where T : Tcp.TcpConnectionMessage
        {
            return from m in messages where m is T select m as T;
        }
    }
}
